package com.li.springbootproject.service.druid;

import com.alibaba.druid.pool.DruidDataSource;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.Map;

@Service
public class DruidServiceImpl implements DruidService {

    private static final Logger logger = LoggerFactory.getLogger(DruidServiceImpl.class);

    @Resource
    private DruidDataSource druidDataSource;

    /**
     * JdbcTemplate 执行Sql的时候每次从底层获取一个新的Connection进行查询
     */
    @Override
    public void jdbctempleteTestOne() {
        JdbcTemplate jdbcTemplate = new JdbcTemplate(druidDataSource);
        for (int i = 0; i < 10; i++) {
            Map<String, Object> map = jdbcTemplate.queryForMap("select 1 as cnt");
            logger.info(map.toString());
        }
        logger.info("test ok!");
    }
}
